package com.tzxs.pay.main.model;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.tzxs.pay.main.MapUtil;

import com.tzxs.pay.util.SystemUtil;

import java.util.HashMap;
import java.util.Map;

public class MerchantInfoGetter {
    private static final int REQUEST_CODE_GET_MERCHANT_INFO = 0;

    public static void getMerchantInfo(Activity activity) {

        if (SystemUtil.getSystemModel().equals("P1") || SystemUtil.getSystemModel().equals("P1_4G") || SystemUtil.getSystemModel().contains("A8")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.shengpay.smartpos.shengpaysdk", "com.shengpay.smartpos.shengpaysdk.activity.MainActivity"));
            intent.putExtra("appId", activity.getPackageName());
            intent.putExtra("barcodeType", "0");
            String amount = null;
            intent.putExtra("amount", amount);
            intent.putExtra("orderNoSFT", "");
            intent.putExtra("reserve47", "");
            intent.putExtra("priInfo", "");
            intent.putExtra("priInfo2", "");
            intent.putExtra("printMerchantInfo", "");
            intent.putExtra("printMerchantInfo2", "");
            intent.putExtra("oldTraceNo", "");
            intent.putExtra("oldReferenceNo", "");
            intent.putExtra("orderDetail", "");
            intent.putExtra("riseString", "");
            intent.putExtra("transName", "10");
            activity.startActivityForResult(intent, REQUEST_CODE_GET_MERCHANT_INFO);
        }
    }

    public static void handleResultForMerchantInfo(Intent data, int requestCode, int resultCode) {
        if (SystemUtil.getSystemModel().equals("P1") || SystemUtil.getSystemModel().equals("P1_4G") || SystemUtil.getSystemModel().contains("A8")) {
            if (data != null) {
                Bundle extras = data.getExtras();
                if (requestCode == REQUEST_CODE_GET_MERCHANT_INFO) {
                    //获取商户信息
                    String terminalId = extras.getString("terminalId");
                    String merchantId = extras.getString("merchantId");
                    String merchantName = extras.getString("merchantName");
                    Log.d("Debug", "terminalId: " + terminalId);
                    Log.d("Debug", "merchantId: " + merchantId);
                    Log.d("Debug", "merchantName: " + merchantName);
                    Map<String, String> map = new HashMap<>();
                    map.put("mac_type", SystemUtil.getSystemModel());
                    map.put("terminalId", terminalId);
                    map.put("merchantId", merchantId);
                    map.put("merchantName", merchantName);
                    MapUtil.getInstance().setMap(map);
                }
            }
        }
    }
}